const cloud = require('wx-server-sdk')
var xlsx = require('node-xlsx');
cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})
function newSheet(sheetdata,sheetname){
  //把数据写入表格
  let newSheet = xlsx.build([
    {
      name:sheetname,
      data:sheetdata
    }
  ])
  return new Promise(function(resolve,reject){
    resolve(cloud.uploadFile({
      cloudPath: 'export/'+sheetname,
      fileContent: newSheet
    }))
  }) 
}

// 云函数入口函数
exports.main = async (event, context) => {
 
  var ws_data =  [
   ['姓名','性别','掌握技能','期望'],
   ['kindear','男','小程序开发','找个工作']
  ];
  return newSheet(ws_data,'test.xlsx');
}